home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbdatabs / sllistb.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-14  |  3.4 KB  |  106 lines

  1. // ------------------------------- //
  2. // -------- Start of File -------- //
  3. // ------------------------------- //
  4. // ----------------------------------------------------------- // 
  5. // C++ Source Code File Name: sbllist.cpp
  6. // Compiler Used: MSVC40, DJGPP 2.7.2.1, GCC 2.7.2.1, HP CPP 10.24
  7. // Produced By: Doug Gaer 
  8. // File Creation Date: 12/29/1996  
  9. // Date Last Modified: 03/15/1999
  10. // Copyright (c) 1997 Douglas M. Gaer
  11. // ----------------------------------------------------------- // 
  12. // ------------- Program Description and Details ------------- // 
  13. // ----------------------------------------------------------- // 
  14. /*
  15. The VBD C++ classes are copyright (c) 1997, by Douglas M. Gaer.
  16. All those who put this code or its derivatives in a commercial
  17. product MUST mention this copyright in their documentation for
  18. users of the products in which this code or its derivative
  19. classes are used. Otherwise, you have the freedom to redistribute
  20. verbatim copies of this source code, adapt it to your specific
  21. needs, or improve the code and release your improvements to the
  22. public provided that the modified files carry prominent notices
  23. stating that you changed the files and the date of any change.
  24.  
  25. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
  26. THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE
  27. IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE,
  28. YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR
  29. CORRECTION.
  30.  
  31. Base classes for singly linked list implementations. The
  32. SNodeBase class and the SDLListBase class separates the
  33. nodes from the data stored in the list by storing pointers
  34. to the data. Classes derived from these base classes can
  35. deal with any type of node data.
  36. */
  37. // ----------------------------------------------------------- // 
  38. #include "sllistb.h"
  39.  
  40. SLListBase::~SLListBase()
  41. {
  42.   // Destructor provided for virtuality
  43. }
  44.  
  45. void SLListBase::MakeEmpty()
  46. {
  47.   SelfRef();
  48.   Back = this;
  49. }
  50.  
  51. void SNodeBase::InsertAfter(SNodeBase *Node)
  52. {
  53.   Node->Next = Next;
  54.   Next = Node;
  55. }
  56.  
  57. SNodeBase *SNodeBase::RmvNext()
  58. {
  59.   SNodeBase *ptr = Next;
  60.   Next = ptr->Next;
  61.   return ptr;
  62. }
  63.  
  64. void SLListBase::Clear()
  65. {
  66.   SNodeBase *Node = Next;
  67.   while(!IsHeader(Node)) {
  68.     SNodeBase *NextNode = Node->Next;
  69.     FreeNode(Node); // Must be defined in derived  classes
  70.     Node = NextNode;
  71.   }
  72.   MakeEmpty();
  73. }
  74.  
  75. SNodeBase *SLListBase::RmvNext(SNodeBase *Node)
  76. {
  77.   if(Node->Next == this) return 0; // Return null if Node is the header
  78.   SNodeBase *ptr = Node->RmvNext();
  79.   if(ptr == Back) Back = Node;
  80.   return ptr; // Remove and return Node pointer
  81. }
  82.  
  83. int SLListBase::Copy(const SLListBase &List)
  84. {
  85.   if(&List == this) return 1; // Already its own copy
  86.   Clear(); // Clear current nodes from this list
  87.   return Cat(List); // 1 if successful, 0 if fails
  88. }
  89.  
  90. int SLListBase::Cat(const SLListBase &List)
  91. {
  92.   if(this == &List) return 0; // Do not append list onto itself
  93.   const SNodeBase *ptr = List.Next;
  94.   while(!List.IsHeader(ptr)) { // For all nodes in List
  95.     SNodeBase *Node = DupNode(ptr);
  96.     if(Node == 0) return 0; // Incomplete copy made
  97.     AttachToBack(Node);
  98.     ptr = ptr->Next;
  99.   }
  100.   return 1; // Successful concatenation
  101. }    
  102. // ----------------------------------------------------------- //
  103. // ------------------------------- //
  104. // --------- End of File --------- //
  105. // ------------------------------- //
  106.